/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.transas.zorlog.data;

/**
 * DataSource helper.
 */
/**
 *
 * @author amalikov
 */
public class Retriever {

	public Retriever(String name, double scale, Modificator mod, double ofs) {
		this.name = name;
		this.scale = scale;
		this.ofs = ofs;
		this.mod = mod;
		this.handle = null;
	}

	public Retriever(String name) {
		this(name, 1, null, 0);
	}

	public Retriever(String name, double scale) {
		this(name, scale, null, 0);
	}

	public Retriever(String name, double scale, Modificator mod) {
		this(name, scale, mod, 0);
	}

	public final double get(DataSource ds, int position) {
		if (handle == null)
			handle = ds.getHandle(name);
		
		final double v = ds.getValue(handle, position);
		return scale * (ofs + (mod != null ? mod.get(v) : v));
	}
	
	private final String name;
	private Object handle;
	private final double scale;
	private final double ofs;
	private final Modificator mod;
	
}
